# -*- coding: utf-8 -*-
"""
@Time    : 2024/6/26 15:33 
@Author  : ZhangShenao 
@File    : pwd.py 
@Desc    : 密码模块
"""
from password_generator.rand_char.random_char import RandomCharacter


def generate_password(length) -> str:
    """
    生成指定长度的密码
    :param length: 密码长度
    :return: 生成的密码
    """
    # 创建随机字符对象
    random_char = RandomCharacter()

    # 生成密码的逻辑:
    # 1位大写字母+1位小写字母+1位数字+1位特殊字符 剩余部分为任意字符
    password = random_char.random_upper_case()
    password += random_char.random_lower_case()
    password += random_char.random_digit()
    password += random_char.random_special_char()
    
    for i in range(5, length):
        password += random_char.random_any()

    return password
